package com.stars.distributed.schedule.demo.demo;

import com.stars.distributed.schedule.DistributedTaskContext;
import com.stars.distributed.schedule.ScheduleTask;
import com.stars.distributed.schedule.DistributedTask;
import com.stars.distributed.schedule.exception.DistributedTaskExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 批量框架实现类DEMO
 *
 * @author GUOGUIFANG
 */
@ScheduleTask("demoTask")
public class TaskDemo implements DistributedTask {

    private static final Logger logger = LoggerFactory.getLogger(TaskDemo.class);

    @Override
    public void execute(DistributedTaskContext distributedTaskContext) throws DistributedTaskExecutionException {
        logger.info("{} -- demoTask 开始执行: ,partition number{},partition count: {}",Thread.currentThread().getName() , distributedTaskContext.getPartitionCount(),distributedTaskContext.getPartitionIndex());
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            logger.debug(e.getMessage(), e);
        }
        logger.info("{} -- demoTask 开始结束",Thread.currentThread().getName());
    }

}